package multigest.vocappulary;

import java.io.IOException;
import java.io.InputStream;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.res.AssetManager;

public class VocAppUtils {

	
	public static JSONObject loadJSONFromAsset(String filepath, AssetManager assetmngr) throws JSONException {
	       
		String json = null;
		
        try {
            InputStream is = assetmngr.open(filepath);
            int size = is.available();
            byte[] buffer = new byte[size];

            is.read(buffer);
            is.close();

            json = new String(buffer, "UTF-8");

        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
        return new JSONObject(json);
    }
	

	public static int getResult(boolean[] results){
		
		int right = 0;
		
		for(int i = 0; i < results.length; i++){
			if(results[i])
				right = right + 1;
		}
				
		return (right*100) / results.length;	
	}
		
	
}
	

